/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.chart;

import com.bean.chart.editors.ChartLegendPosition;
import com.bean.chart.iterfaces.AbstractChart;
import com.bean.chart.iterfaces.AbstractChartComposite;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.swing.JPanel;

/**
 *
 * @author Lukasz
 */
public class ChartComposite extends AbstractChartComposite implements Serializable{

    private PropertyChangeSupport propertySupport;
    private AbstractChart chart;
    private ChartLabel chartTitle;
    private ChartLegend chartLegend;

    public ChartComposite(){
        propertySupport = new PropertyChangeSupport(this);
        chart = new Chart();
        chartTitle = new ChartLabel();
        chartLegend = new ChartLegend();
        this.add(panelChartTitle(), BorderLayout.CENTER);
        addChartLegend();
        
    }
    
    private JPanel panelChartTitle(){
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(1, 0, 30, 0));
        panel.add(chartTitle);
        panel.add(chart);
        return panel;
    }
    private void addChartLegend(){
        if(this.getLegendPosition() == ChartLegendPosition.DOWN)
            this.add(chartLegend, BorderLayout.SOUTH);
        if(this.getLegendPosition() == ChartLegendPosition.UP)
            this.add(chartLegend, BorderLayout.NORTH);
        if(this.getLegendPosition() == ChartLegendPosition.LEFT)
            this.add(chartLegend, BorderLayout.WEST);
        if(this.getLegendPosition() == ChartLegendPosition.RIGHT)
            this.add(chartLegend,BorderLayout.EAST);
    }
    @Override
    protected void propertyChange(String property, boolean oldval, boolean newVal) {
        propertySupport.firePropertyChange(property, oldval, newVal);
    }

    @Override
    protected void propertyChange(String property, String oldval, String newVal) {
        propertySupport.firePropertyChange(property, oldval, newVal);
    }

    @Override
    protected void propertyChange(String property, ChartLegendPosition oldval, ChartLegendPosition newVal) {
        propertySupport.firePropertyChange(property, oldval, newVal);;
    }
    
}
